473,441 Members | 1,336 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,441 software developers and data experts.

XML Creating nodes

Hi there,

just wondering if someone could help me. Ive written some code in
vb.net to create the following xml.

<menu>
<menuItem>
<text>Political Update</text>
</menuItem>
<subMenu />
<menuItem>
<text>sub categoruy 1</text>
<url>1</url>
</menuItem>
<menuItem>
<text>sub categoruy 2</text>
<url>3</url>
</menuItem>
<menuItem>
<text>sub categoruy 3</text>
<url>4</url>
</menuItem>
</menu>

what i actually want to do is to add the 'subMenu' item into the xml
like the following. im not sure whow to do this as im building my xml
up by looping through a couple of datasets.

<menu>
<menuItem>
<text>Political Update</text>
</menuItem>
<subMenu>
<menuItem>
<text>sub categoruy 1</text>
<url>1</url>
</menuItem>
<menuItem>
<text>sub categoruy 2</text>
<url>3</url>
</menuItem>
<menuItem>
<text>sub categoruy 3</text>
<url>4</url>
</menuItem>
<subMenu />
</menu>

any help appreciated

CG

Oct 21 '06 #1
2 6220
i just also want to point out that i sued the following code to create
the element subMenu inthe first piece of XML

objXMLGrandchildNode = oXMLValueDoc.CreateNode("element",
"subMenu", "")
objXMLChildNode.appendChild(objXMLGrandchildNode)

what code is required to create the secont piece of XML ????

Thanks

Colin


csgraham74 wrote:
Hi there,

just wondering if someone could help me. Ive written some code in
vb.net to create the following xml.

<menu>
<menuItem>
<text>Political Update</text>
</menuItem>
<subMenu />
<menuItem>
<text>sub categoruy 1</text>
<url>1</url>
</menuItem>
<menuItem>
<text>sub categoruy 2</text>
<url>3</url>
</menuItem>
<menuItem>
<text>sub categoruy 3</text>
<url>4</url>
</menuItem>
</menu>

what i actually want to do is to add the 'subMenu' item into the xml
like the following. im not sure whow to do this as im building my xml
up by looping through a couple of datasets.

<menu>
<menuItem>
<text>Political Update</text>
</menuItem>
<subMenu>
<menuItem>
<text>sub categoruy 1</text>
<url>1</url>
</menuItem>
<menuItem>
<text>sub categoruy 2</text>
<url>3</url>
</menuItem>
<menuItem>
<text>sub categoruy 3</text>
<url>4</url>
</menuItem>
<subMenu />
</menu>

any help appreciated

CG
Oct 22 '06 #2
csgraham74 wrote:
<menu>
<menuItem>
<text>Political Update</text>
</menuItem>
<subMenu>
<menuItem>
<text>sub categoruy 1</text>
<url>1</url>
</menuItem>
<menuItem>
<text>sub categoruy 2</text>
<url>3</url>
</menuItem>
<menuItem>
<text>sub categoruy 3</text>
<url>4</url>
</menuItem>
<subMenu />
</menu>
Assuming you have a System.Xml.XmlDocument instance or a
System.Xml.XmlDataDocument instance you can do e.g.

Dim Xml_Doc As XmlDocument = New XmlDocument
Xml_Doc.Load("XMLFile1.xml")
Dim SubMenu As XmlNode = _
Xml_Doc.SelectSingleNode("menu/subMenu")
Dim MenuItems As XmlNodeList = _
SubMenu.SelectNodes("following-sibling::node()")
For I As Integer = MenuItems.Count - 1 To 0 Step -1
SubMenu.InsertBefore(MenuItems(I), SubMenu.FirstChild)
Next
' Now save back e.g.
Xml_Doc.Save("XMLFile2.xml")

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Oct 22 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Jeffrey Silverman | last post by:
Hi, all. I have a linked list. I need an algorithm to create a tree structure from that list. Basically, I want to turn this: $list = array( array( 'id' => 'A', 'parent_id' => null, 'value'...
4
by: Altramagnus | last post by:
I have 30 - 40 type of different window. For each type I need about 20 instances of the window. When I try to create them, I get "Error creating window handle" My guess is there is a maximum...
3
by: NoLongerMicah | last post by:
I have derived new classes for the TreeNode and TreeView classes that Microsoft provides. Since the TreeNodeCollection class is sealed I created my own class that implements the IList interface. ...
4
by: Amit Bhatia | last post by:
User-Agent: OSXnews 2.081 Xref: number1.nntp.dca.giganews.com comp.lang.c++:817424 Hi, I have posted this post also for the thread "vector of lists" but since it is about something else...
5
by: Marcin Gil | last post by:
Hi! I have the code like this (obvious things like ctor/dtor removed) typedef struct _NODE { int val; int index; } Node;
2
by: RickH | last post by:
Using the ms XMLDOM... What techniques do you guys use to create deep elements in code for appending to the main document as the user "adds" complex objects. Currently I keep 3 files to do it...
8
by: arunrocks | last post by:
Hi I am having a requirement to create a db in 2 out of 8 partitiones. I have the following doubts. 1. should I create a new instance in 2 partitions alone (the present instance spans 8 nodes)...
2
by: Polaris431 | last post by:
I need to implement a tree structure that can accept various types of classes or structs. When the tree is created, all of its nodes are based on a single type and not a mixture of types. ...
10
by: John Rogers | last post by:
This code only counts the parent nodes or rootnodes in a treeview, how do you count all the nodes in a treeview? // one way int NodeCounter = 0; foreach (TreeNode currentNode in...
1
by: Sumz | last post by:
what would the syntax be to create new parent and child nodes to an existing tree view. i just need to create text and not link to any where. these nodes would be created at runtime with a button.
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.